#!/bin/bash

# Keep the current folder
curdir=`pwd`

# find the root dir
while [ ! -d ".git" ]; do
    cd ..
done

echo "Root dir is set to $(pwd)"

# Clear old installers
os_name=`uname -s`
arch=`uname -m`

os_name=`uname -s`
echo rm -f $curdir/build-release/codelite.app.tar.gz
rm -f $curdir/build-release/codelite.app.tar.gz

if [[ "$os_name" == "Darwin" ]]; then
    cpu_count=$(sysctl -n hw.ncpu)
elif [[ "$os_name" == "Linux" ]]; then
    cpu_count=$(nproc)
fi

## parse the command line arguments and over defaults
for i in "$@"
do
    case $i in
    --version=*)
        version="${i#*=}"
        shift
        ;;
    esac
done

if [ -z ${version} ]; then
    echo -e "ERROR: please provide version. e.g. --version=16.5.0"
    exit 1
fi

echo "Platform      : ${os_name}"
echo "CPU count     : ${cpu_count}"
echo "Verison       : ${version}"

# Update our source tree
cd $curdir
echo "Pulling CodeLite changes..."
echo `pwd`
git pull --rebase --recurse-submodules
if [ $? -ne 0 ]; then
    exit $?
fi

cd $curdir
ORIG_PATH=$PATH
ORIG_LDPATH=$LD_LIBRARY_PATH
ROOT_DIR=$(pwd)

upload_path="/var/www/html/downloads/codelite/${version}"
